<template>
  <div id="box">
    <div class="box-center">
      <ul>
        <li><router-link to="/">首页</router-link></li>
        <li><router-link to="/pages/news">新闻</router-link></li>
        <li><router-link to="/pages/keji">科技</router-link></li>
      </ul>
      <div class="img" v-if="isLogin">
        <img src="@/assets/twl.jpg">
      </div>
      <div class="btns" v-else>
        <el-button @click="login" type="primary" v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="正在登陆 ...">登录</el-button>
        <el-button>注册</el-button>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'header',
  data () {
    return {
      fullscreenLoading: false,
      isLogin: false
    }
  },
  mounted () {
    // console.log(this.$store.state.userInfo)
  },
  methods: {
    login () {
      this.fullscreenLoading = true
      setTimeout(() => {
        this.fullscreenLoading = false
        this.isLogin = true
        this.$message({
          message: '恭喜你，登陆成功！',
          type: 'success',
          offset: 100
        })
        this.$store.commit('setUserInfo', { userId: 'yx100', userName: '永祥' })
      }, 3000)
    }
  }
}
</script>

<style scoped lang="less">
#box{
  .box-center{
    width: 1100px;
    margin: 0 auto;
    overflow: hidden;
    .img{
      img{
        float: right;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        margin-top: 10px;
      }
    }
    ul{
    float: left;
    overflow: hidden;
    li{
      float: left;
      margin-right: 50px;
      color: #fff;
      cursor: pointer;
    }
  }
  .btns{
    float: right;
    height: 50px;
    margin-top: 10px;
  }
  }
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: #666;
}
</style>
